import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/**
 * 用于接收来自native的调用
 */
class FlutterMethod {
  static const MethodChannel methodChannel =
      MethodChannel("module/event", JSONMethodCodec());

  BuildContext? context = null;

  FlutterMethod(BuildContext? context) {
    this.context = context;
    methodChannel.setMethodCallHandler(_handleNavigationInvocation);
  }



  Future<dynamic> _handleNavigationInvocation(MethodCall methodCall) {
    switch (methodCall.method) {
      case 'callFlutter':
        print('native call Flutter!！');
        print(methodCall.arguments);
        var alertDialog = AlertDialog(
          title: Text("title"),
          content: Text(methodCall.arguments.toString()),
        );
        showDialog(
            context: context!, builder: (BuildContext context) => alertDialog);
    }
    return Future<dynamic>.value();
  }
}
